package com.dongfg.zcmserver.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * API.
 * Created by 13071472 on 2015/11/6.
 */
@Controller
@RequestMapping("/api")
public class ApiController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ApiController.class);

    @RequestMapping(value = "/{version}/nodes", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity<String> getNodes(@PathVariable String version) {
        return new ResponseEntity<>(JSON.toJSONString(new Date(), SerializerFeature.WriteDateUseDateFormat), HttpStatus.OK);
    }

    @RequestMapping(value = "/{version}/nodes", method = RequestMethod.POST)
    @ResponseBody
    public String addNodes(@PathVariable String version) {
        return JSON.toJSONString(new Date(), SerializerFeature.WriteDateUseDateFormat);
    }

    @RequestMapping(value = "/{version}/nodes/{path}", method = RequestMethod.GET)
    @ResponseBody
    public String getNode(@PathVariable String version, @PathVariable String path) {
        return JSON.toJSONString(new Date(), SerializerFeature.WriteDateUseDateFormat);
    }

    @RequestMapping(value = "/{version}/nodes/{path}", method = RequestMethod.PUT)
    @ResponseBody
    public String updateNode(@PathVariable String version, @PathVariable String path) {
        return JSON.toJSONString(new Date(), SerializerFeature.WriteDateUseDateFormat);
    }

    @RequestMapping(value = "/{version}/nodes/{path}", method = RequestMethod.DELETE)
    @ResponseBody
    public String deleteNode(@PathVariable String version, @PathVariable String path) {
        return JSON.toJSONString(new Date(), SerializerFeature.WriteDateUseDateFormat);
    }

}
